package com.dyz.leetcode._16_dataStructureDesign;

import java.util.Stack;

public class _30_offer_minStack {

    private Stack<Integer> stack1;
    private Stack<Integer> minStack;
    public _30_offer_minStack() {
        this.stack1 = new Stack<>();
        this.minStack = new Stack<>();
    }

    public void push(int x) {
        stack1.push(x);
        if(minStack.isEmpty() || minStack.peek()>=x){
            minStack.push(x);
        }
    }

    public void pop() {
        int pop = stack1.pop();
        if(pop==minStack.peek()){
            minStack.pop();
        }
    }

    public int top() {
        return stack1.peek();
    }

    public int min() {
        if(minStack.isEmpty()){
            return -1;
        }
        return minStack.peek();

    }

}
